package cn.znzz.cjm.product.service.impl;


import cn.znzz.cjm.basic.service.impl.BaseServiceImpl;
import cn.znzz.cjm.product.domain.Product;
import cn.znzz.cjm.product.domain.ProductDetail;
import cn.znzz.cjm.product.mapper.ProductDetailMapper;
import cn.znzz.cjm.product.mapper.ProductMapper;
import cn.znzz.cjm.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ProductDetailMapper productDetailMapper;

    @Override
    public void add(Product product) {
        //保存服务信息
        productMapper.save(product);
        //保存服务基本信息
        ProductDetail detail = product.getDetail();
        if(detail !=null){
            detail.setProduct_id(product.getId());
            productDetailMapper.save(detail);
        }
    }

    @Override
    public void onSale(List<Long> ids) {
        Map<String,Object> map=new HashMap<>();
        map.put("ids",ids);
        map.put("onSaleTime",new Date());
        productMapper.onSale(map);
    }

    @Override
    public void offSale(List<Long> ids) {
        Map<String,Object> map=new HashMap<>();
        map.put("ids",ids);
        map.put("offSaleTime",new Date());
        productMapper.offSale(map);
    }

    @Override
    public Product queryByIdDetail(Long id) {
        return productMapper.loadByIdDetail(id);
    }
}
